//
//  ReadingViewController.m
//  CollectionViewDemo
//
//  Created by liuchengming on 16/12/16.
//  Copyright © 2016年 liuchengming. All rights reserved.
//

#import "ReadingViewController.h"
#import "ContentViewController.h"

@interface ReadingViewController () <UIPageViewControllerDelegate,UIPageViewControllerDataSource>

@property (strong,nonatomic) UIPageViewController * pageViewController;

@end

@implementation ReadingViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.toolbarHidden = YES;
    
    //NSDictionary * options = @{UIPageViewControllerOptionInterPageSpacingKey:@(20)};
    _pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
    _pageViewController.delegate = self ;
    _pageViewController.dataSource = self;
    
    
    //init
    ContentViewController * con = [ContentViewController new];
    
    con.textContent = _string;
    
    [_pageViewController setViewControllers:@[con] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
    
    
    
    _pageViewController.view.frame = self.view.bounds;
    //
    [self addChildViewController:_pageViewController];
    [self.view addSubview:_pageViewController.view];
    [self Menu];
}


- (nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    
    return nil;
}

-(nullable UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    UITextView * size = [UITextView new];
    size.frame = [UIScreen mainScreen].bounds;
    ContentViewController * con = [ContentViewController new];
    con.textContent = _string ;
    con.textView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height+568);
    return con;
}

- (void)Menu
{
    RNSwipeBar *swipeBar = [[RNSwipeBar alloc] initWithMainView:[self view]];
    [swipeBar setPadding:20.0f];
    [swipeBar setDelegate:self];
    [self setSwipeBar:swipeBar];
    [[self view] addSubview:[self swipeBar]];
    
    RNBarView *barView = [[[NSBundle mainBundle] loadNibNamed:@"RNBarView" owner:self options:nil] lastObject];
    [barView setDelegate:self];
    [swipeBar setBarView:barView];
    
    
    UIButton * btn = [UIButton new];
    [btn setTitle:@"返回书架" forState:0];
    btn.frame = CGRectMake(0, 30, 80, 44);
    [btn addTarget:self action:@selector(ReturnMianView) forControlEvents:UIControlEventTouchUpInside];
    [barView addSubview:btn];
    
}


- (void)ReturnMianView
{
    [self dismissViewControllerAnimated:YES completion:nil];
}



- (void)mainButtonWasPressed:(id)sender
{
    [self.swipeBar toggle];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
